package com.ruoyi.worklog.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.worklog.model.ReqWlStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.worklog.domain.WlWorkLog;
import com.ruoyi.worklog.service.WlWorkLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
 * @Author cw
 * @Date 2022/7/22 - 07 - 22
 * @Description com.ruoyi.worklog.controller
 */

@RestController
@RequestMapping("/worklog/log")
public class workLogControllter extends BaseController{
    @Autowired
    private WlWorkLogService wlWorkLogService;

    /**
     * 查询日志列表
     */
    //@PreAuthorize("@ss.hasPermi('worklog:log:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody WlWorkLog wlWorkLog)
    {
        startPage();
        List<WlWorkLog> list = wlWorkLogService.selectWlWorkLogList(wlWorkLog);
        return getDataTable(list);
    }

    /**
     * 导出日志列表
     */
    //@PreAuthorize("@ss.hasPermi('worklog:log:export')")
 /*   @Log(title = "日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WlWorkLog wlWorkLog)
    {
        List<WlWorkLog> list = wlWorkLogService.selectWlWorkLogList(wlWorkLog);
        ExcelUtil<WlWorkLog> util = new ExcelUtil<WlWorkLog>(WlWorkLog.class);
        util.exportExcel(response, list, "日志数据");
    }*/

    /**
     * 获取日志详细信息
     */
    //@PreAuthorize("@ss.hasPermi('worklog:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wlWorkLogService.selectWlWorkLogById(id));
    }

    /**
     * 新增日志
     */
    //@PreAuthorize("@ss.hasPermi('worklog:log:add')")
//    @Log(title = "日志", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    @Transactional(rollbackFor=Exception.class)
    public AjaxResult add(@Validated @RequestBody WlWorkLog wlWorkLog)
    {
        return toAjax(wlWorkLogService.insertWlWorkLog(wlWorkLog));
    }

    /**
     * 修改日志
     */
    //@PreAuthorize("@ss.hasPermi('worklog:log:edit')")
    @Log(title = "日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WlWorkLog wlWorkLog)
    {
        return toAjax(wlWorkLogService.updateWlWorkLog(wlWorkLog));
    }


    /**
     * 删除日志
     */
//    @PreAuthorize("@ss.hasPermi('worklog:log:remove')")
//    @Log(title = "日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    @Transactional(rollbackFor=Exception.class)
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        System.out.println(ids);
        return toAjax(wlWorkLogService.deleteWlWorkLogByIds(ids));
    }

}
